package com.lm.activiti.boot.tools;

/**
 * @author lm_jcf
 * @date 2018/11/8 14:04
 */
public class BDCoordinate {


    // 圆周率
    private static final Double PI = Math.PI;

    private static final Double PK = 180/PI;

    public static double getDistanceByCoordinate(double lng_a, double lat_a, double lng_b, double lat_b) {

        double t1 = Math.cos(lat_a / PK) * Math.cos(lng_a / PK) * Math.cos(lat_b / PK) * Math.cos(lng_b / PK);

        double t2 = Math.cos(lat_a / PK) * Math.sin(lng_a / PK) * Math.cos(lat_b / PK) * Math.sin(lng_b / PK);

        double t3 = Math.sin(lat_a / PK) * Math.sin(lat_b / PK);

        double tt = Math.acos(t1 + t2 + t3);
        System.out.println(6370996.81 * tt);

        return 6370996.81 * tt;
    }

    // 地球半径
    private static final double EARTH_RADIUS = 6370996.81;

    // 弧度
    private static double radian(double d) {
        return d * Math.PI / 180.0;
    }

    public static void distanceOfTwoPoints(double lng1, double lat1, double lng2, double lat2) {

        double radLat1 = radian(lat1);
        double radLat2 = radian(lat2);
        double a = radLat1 - radLat2;
        double b = radian(lng1) - radian(lng2);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
                + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        double ss = s * 1.0936132983377;
        System.out.println("两点间的距离是：" + s + "米" + "," + (int) ss + "码");
    }

    public static void main(String[] args) {

        getDistanceByCoordinate(113.379623,23.131893, 113.363049,23.140642);
//        distanceOfTwoPoints(113.363049,23.140717, 113.355809,23.139774);

    }


}
